from utils.db_tools import read_db


class UserCheck(object):

    @classmethod
    def get_daily_users(cls):
        sql = "SELECT user_code,user_name,check_start,check_end from user_check where is_valid=1 and check_type > 0"
        pdf = read_db(sql)
        pdf = pdf.set_index("user_code")
        return pdf.to_dict(orient='index')

    @classmethod
    def get_check_user(cls):
        sql = "SELECT user_code, user_name,zk_id,wx_id,check_type FROM user_check WHERE is_valid=1 AND check_type>=1"
        pdf = read_db(sql)
        data = {"user": {}, "wx": [], "zk": []}
        for row in pdf.itertuples():
            if row.check_type == 1:
                data['zk'].append(row.zk_id)
                data['user'][int(row.zk_id)] = {'user_code': row.user_code, 'user_name': row.user_name}
            if row.check_type >= 2:
                data['wx'].append(row.wx_id)
                data['user'][row.wx_id] = {'user_code': row.user_code, 'user_name': row.user_name}
        return data


if __name__ == '__main__':
    print(UserCheck.get_check_user()['wx'])
